package strings

import (
	"fmt"
	"strings"
	"unicode/utf8"
)

func main() {
	s := "Yes我爱慕课网!"
	fmt.Println("byte长度", len(s))
	//fmt.Printf("%X\n", []byte(s))
	for _, b := range []byte(s) {
		fmt.Printf("%X ", b)
	}
	fmt.Println()
	for i, ch := range s { // ch is a rune
		fmt.Printf("(%d %X)", i, ch)
	}
	fmt.Println()
	fmt.Println(utf8.RuneCountInString(s)) // 获得字符数量

	bytes := []byte(s)
	for len(bytes) > 0 {
		ch, size := utf8.DecodeRune(bytes) // byte解码为rune
		bytes = bytes[size:]
		fmt.Printf("%c ", ch)
	}
	fmt.Println()

	for i, ch := range []rune(s) {
		// 转为rune类型的切片
		fmt.Printf("(%d %c)", i, ch)
	}
	fmt.Println()
	// strings 包对字符串的操作
	s1 := "1,2,3,4,5"
	res := strings.Split(s1, ",") // 切片
	fmt.Println(res[1])
}
